<template>
  <div class="wrapper">
    <div class="title-wrapper">
      <div class="bigTitle">财务统计</div>
      <div style="text-align: right">
        <time-picker ref="timeRef" @change="handleChange" />
      </div>
    </div>
    <financial-bar :source="manData"/>
  </div>
</template>

<script>
import {bsfsCount} from "@/api/services/dashboard.service";
import financialBar from './financial-bar'
import moment from "moment";
import timePicker from './time-picker'

export default {
  name: "financial",
  components: {financialBar,timePicker},
  data() {
    return {
      manData: {},
      currentTime: '',
    }
  },

  mounted() {
    this.$nextTick(() => {
      let time = this.$refs.timeRef.initTime()
      this.handleChange(time)
    })
  },
  methods: {
    handleChange(data) {
      if (!data) return
      this.currentTime = `${data.year}-${data.moment}`
      this.getData()
    },
    getData() {
      let currentTime = this.currentTime
      let params = {stime: '', etime: ''}
      let month = moment(this.currentTime, "YYYY-MM").daysInMonth()
      if (currentTime) {
        params.stime = `${currentTime}-01 00:00:00`
        params.etime = `${currentTime}-${month} 23:59:59`
      }
      bsfsCount(params).then(res => {
        const {bankTrade, staffReim, servicePay, serviceGath} = res
        this.manData = {
          xAxisData: ['银行记账', '员工报账', '业务付款', '业务收款'],
          done: [bankTrade.alOper, staffReim.alOper, servicePay.alOper, serviceGath.alOper],
          notDone: [bankTrade.noOper, staffReim.noOper, servicePay.noOper, serviceGath.noOper]
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.title-wrapper {
  justify-content: space-between;

  .bigTitle {
    border-bottom: none;
    padding: 8px 0;
    color: #3A71A8;
    font-size: 18px;
    font-weight: bold;
    white-space: nowrap;
  }
}

.total_wrapper {
  width: 80%;
  margin: 0 auto;
  display: flex;
  align-items: center;

  .item {
    flex: 1;
    text-align: center;
  }
}

.wrapper {
  width: 100%;

}
</style>
